package com.czy.owner.ui.illegalquery;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.adapter.IllegalQueryDetailAdapter;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.entity.IllegalQueryDetailModel;
import com.czy.owner.rxbus.IllegalEvent;
import com.czy.owner.rxbus.RxBus;
import com.czy.owner.ui.BaseActivity;
import com.easyrecycleview.EasyRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wangyang on 2016/12/8 0008.
 * 违章查询详情
 */
public class IllegalQueryDetailActivity extends BaseActivity {
    @BindView(R.id.easy_recycleview)
    EasyRecyclerView recyclerView;
    @BindView(R.id.toolbar_right_title)
    TextView toolbarRightTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    private IllegalQueryDetailAdapter adapter;
    private List<IllegalQueryDetailModel> list = new ArrayList<>();

    @Override
    protected int attachLayoutRes() {
        return R.layout.common_activity_illegal_easyrecycleview;
    }

    @Override
    protected void initInjector() {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
//        getToolbarTitle().setText("");
        getSupportActionBar().setTitle("");
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
//            DialogUtils.showDateSuccessDialog(this, type, "你的工单尚未完成支付\n是否放弃支付？", "放弃支付", "继续支付");
            RxBus.getDefault().post(new IllegalEvent("2"));
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void initViews() {

        toolbarTitle.setText("违章记录");

        toolbarRightTitle.setText("再次查询");
        list = (List<IllegalQueryDetailModel>) getIntent().getSerializableExtra("list");
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapterWithProgress(adapter = new IllegalQueryDetailAdapter(this));
        recyclerView.addItemDecoration(new RecycleViewDivider(IllegalQueryDetailActivity.this, LinearLayoutManager.VERTICAL, R.drawable.shape_recyclerview_divider_decoration));
        recyclerView.setErrorView(R.layout.view_error_refresh);
        adapter.addAll(list);
        if (adapter.getAllData().size() == 0) {
            recyclerView.setEmptyView(R.layout.recycleview_illegal_query_empty_view);
            recyclerView.showEmpty();
            ImageView imageView = (ImageView) recyclerView.getEmptyView().findViewById(R.id.img_default);
            imageView.setImageResource(R.mipmap.the_record_is_empty);
        }
    }

    @Override
    protected void updateViews() {

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.toolbar_title, R.id.linear_right_text})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.toolbar_title:
                break;
            case R.id.linear_right_text:
                RxBus.getDefault().post(new IllegalEvent("1"));
                finish();

                break;
        }
    }
}
